<div class="breadcrumbs ace-save-state" id="breadcrumbs">
	<ul class="breadcrumb">
		<li>
			<i class="ace-icon fa fa-list"></i>
			<a href="javascript:void(0)">权限设置</a>
		</li>
		<li class="active">用户组</li>
	</ul><!-- /.breadcrumb -->

	<div class="nav-search" id="nav-search">
		<form class="form-search">
            <span class="input-icon">
                <input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off"/>
                <i class="ace-icon fa fa-search nav-search-icon"></i>
            </span>
		</form>
	</div><!-- /.nav-search -->
</div>

<div class="page-content">

	<div class="row">
		<div class="col-xs-12">
			<!-- PAGE CONTENT BEGINS -->
			<table id="group-grid-table"></table>
			<div id="group-grid-pager"></div>
			<!-- PAGE CONTENT ENDS -->
		</div><!-- /.col -->

	</div><!-- /.row -->

</div><!-- /.page-content -->


<script type="text/javascript">

	group_page_init();

	function group_page_init() {
		var grid_selector = "#group-grid-table";
		var pager_selector = "#group-grid-pager";


		// 初始化
		var grid_config ={{ grid_config|safe }};

		function style_edit_form_field(form) {

		}

		// 操作列
		function formatMyAc(cellValue, options, rowObject, state) {
			var detail = '<div title="设置权限" style="float:left;cursor:pointer;" ' +
				'class="ui-pg-div ui-inline-edit"' +
				'onclick="showSetPermission(' + rowObject.id + ');" ' +
				'onmouseover="jQuery(this).addClass(\'ui-state-hover\');" ' +
				'onmouseout="jQuery(this).removeClass(\'ui-state-hover\');">' +
				'<span class="ui-icon ui-icon-pencil"></span>' +
				'</div>';

			return '<div style="margin-left:8px;">' + detail + '</div>'
		}

		JqGridHelp.updateColModel(grid_config, "myac", {formatter: formatMyAc});

		var jqGridHelp = JqGridHelp.createNew(grid_selector, pager_selector, grid_config, style_edit_form_field, {edit: true, add: true, del: true, search: true, refresh: true, view: true});
	}

	// 设置权限
	function showSetPermission(role_id) {
		function callback(data, status, xhr) {
			if (status == "success") {
				showSetPermissionDialog(data);
			} else {
				showSetPermissionDialog("错误信息: <br/>" + xhr.status + " " + xhr.statusText)
			}
		}

		$.get("setting/group_set_permission_view", {role_id: role_id}, callback);
	}

	function showSetPermissionDialog(content) {
		var layer = layui.layer;
		var that = this;
		//多窗口模式，层叠置顶
		layer.open({
			type: 1
			, title: '设置权限：'
			, area: ['600px', '400px']
			, shade: 0
			, maxmin: true
			, offset: "auto"
			, content: content
			, btn: ['确定', '取消']
			, yes: function () {
				var permData = formserializeJson('set_permissions_form');
				submitPermission(layer, permData);
				return false;
			}
			, btn2: function () {
				layer.closeAll();
				return true;
			}
			, zIndex: layer.zIndex //重点1

			, success: function (layero) {
				layer.setTop(layero); //重点2
			}
			, end: function () {
			}
		});
	}

	// 提交权限设置
	function submitPermission(layer, permData) {
		console.log(permData);

		function callback(data, status, xhr) {
			if (status == "success") {
				if (data.result == 0) {
					alert(data.reason);
				} else {
					alert(data.reason);
				}
			} else {
				// resetValidateCode()
				alert("错误信息: <br/>" + xhr.status + " " + xhr.statusText)
			}
			layer.closeAll();
		}

		var url = "/smAdmin/setting/group_set_permissions";
		$.post(url, permData, callback, 'json');
	}


</script>